#######################################################
# Example of PingPong coupled DEVS using DEVS player
# Author: moonho.hwang@gmail.com
#   Date: Oct.19.2011
#######################################################
from XSY.DEVS.Simulatable import *
from XSY.DEVS.CoupledDEVS import *
from XSY.DEVS.SimEngine import SimEngine
from Player import Player

def makeModel():
   '''create a coupled DEVS modle of a pingpong game'''
   md1 = Player(name='A', init='S')
   md2 = Player(name='B', init='W')

   cm = CoupledDEVS("PingPong")
   cm.addComponents(md1, md2)
   cm.addCouples((md1.OP["!s"], md2.IP["?r"]), (md2.OP["!s"], md1.IP["?r"]))
   return cm

if __name__ == '__main__':
   cm = makeModel() # step 1.
   #print 'isNetworkOf(Player)=', cm.isNetworkOf(Player)
   engine = SimEngine(cm) # step 2.
   engine.runInteractiveMenu() # step 3.
